#include "StdAfx.h"
#include "GridRow.h"

CGridRow::CGridRow(CGridListDraw *pGridDarw,int nCount)
{
	XXRc		=CRect(0,0,0,0);
	m_AllRect	=CRect(0,0,0,0);
	m_blExpand	=0;
	m_pGridListDarw=pGridDarw;
	for (int i=0;i<nCount;i++)
	{	
		m_ItemS.push_back(new CGridBaseItem(this));
	}
}
CGridRow::~CGridRow(void)
{
	int nSizeItem=m_ItemS.size();
	for(int i=0;i<nSizeItem;i++)
	{
		delete m_ItemS[i];
	}
	m_ItemS.clear();
	int nSizeRow=vChildRow.size();
	for (int n=0;n<nSizeRow;n++)
	{
		delete vChildRow[n];
	}
	vChildRow.clear();
}
BOOL CGridRow::AddSubRow(CGridRow *pSubRow)
{
	pSubRow->m_AttachRow=this;
	vChildRow.push_back(pSubRow);
	return TRUE;
}
BOOL CGridRow::DelSubRow(int nSubIndex)
{
	int nSize=(int)vChildRow.size();
	if (nSize>nSubIndex)
	{
		CGridRow *pDelRow=*(vChildRow.begin()+nSubIndex);
		vChildRow.erase(vChildRow.begin()+nSubIndex);
		delete pDelRow;
		return TRUE;
	}
	return FALSE;
}
CGridRow*CGridRow::GetSubRow(int nSubIndex)
{
	int nSize=(int)vChildRow.size();
	if (nSize>nSubIndex)
	{
		return vChildRow[nSubIndex];
	}
	return NULL;
}
CGridBaseItem* CGridRow::GetItem(int nIndex)
{
	int nSize=(int)m_ItemS.size();
	if (nSize>nIndex)
	{
		return m_ItemS[nIndex];
	}
	return NULL;
}
BOOL CGridRow::ReplaceItem(int nIndex,CGridBaseItem *pNewItem,BOOL bRedraw)
{
	int nSize=(int)m_ItemS.size();
	if (nSize>nIndex)
	{
		pNewItem->m_AttachRow=this;
		CGridBaseItem *pOldItem=m_ItemS[nIndex];
		m_ItemS[nIndex]=pNewItem;
		delete pOldItem;

		if (bRedraw)
		{
			pNewItem->Redraw();
		}
		return TRUE;
	}
	return FALSE;
}